#include "IOuter.h"

namespace WLog
{
	IOuter::IOuter(std::ostream *pOs)
		:m_pOs(pOs),m_state(HAVENT_PARPARED)
	{
		m_state = HAVE_PARPARED;
		noticeParpareOut();
	}

	IOuter::~IOuter()
	{
		noticeEndOut();	
	}

	void IOuter::noticeParpareOut()
	{
		if (HAVE_PARPARED == m_state)
		{
			m_state = HAVENT_ENDOUT;
		}
	}
		
	void IOuter::noticeEndOut()
	{
		if (HAVENT_ENDOUT == m_state)
		{
			m_state = HAVE_ENDOUT;
		}
	}

	void IOuter::out(string strOut)
	{
		if (m_pOs)
		{
			(*m_pOs) << strOut;
			(*m_pOs).flush();
		}
	}
	
	void IOuter::outendl()
	{
		if (m_pOs)
		{
			(*m_pOs) << std::endl;
		}
	}

	std::ostream* IOuter::setOstream(std::ostream *pOs)
	{
		std::ostream* pLastOs = this->m_pOs;
		this->m_pOs = pOs;
		return pLastOs;
	}

	std::ostream* IOuter::getOstream()
	{
		return this->m_pOs;
	}
}
